package com.dingwei.lesyndrome.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;

import com.bumptech.glide.Glide;
import com.dingwei.lesyndrome.R;
import com.luck.picture.lib.photoview.PhotoView;

import java.util.ArrayList;
import java.util.List;

public class ImagePageAdapter extends PagerAdapter {

	private List<String> mlist = new ArrayList<>();
	private LayoutInflater inflater;
	private Context context;

	public ImagePageAdapter(Context context, List<String> mlist) {
		// TODO Auto-generated constructor stub
		this.mlist = mlist;
		inflater = LayoutInflater.from(context);
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (null != mlist) {
			return mlist.size();
		}
		return 0;
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		// TODO Auto-generated method stub
		return view == object;
	}

	@SuppressLint("InflateParams")
	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.lifedetail_pager_item, null);
		PhotoView photoView = (PhotoView) view.findViewById(R.id.image);



		Glide.with(context).load(mlist.get(position))
					.into(photoView);
		// Now just add PhotoView to ViewPager and return it
		container.addView(view, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		return view;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		// TODO Auto-generated method stub
		container.removeView((View) object);
	}

}
